Namespace("org.wattdepot.gdata.makahiki");

// Creates a Gauge with a standard appearance for the Makahiki application. 
org.wattdepot.gdata.makahiki.Gauge = function(configuration) {

  var gaugeSize = configuration.gaugeWidth;

  function draw(datatable, row, columns, id, maxValue) {
    var element = document.getElementById(id);
    // Color the gauge green from 0 to 50% of maxValue, yellow from 50% to 75%, red from 75% to 100%.
    var maxGreen = maxValue * .50;
    var maxYellow = maxValue * .75; 

    // Blank out the title cell because it will be displayed outside the Gauge
    datatable.setCell(row, columns[0], '');

    // Create a view consisting of the two columns and a single row as the data to the gauge.
    var chartView = new google.visualization.DataView(datatable);
    chartView.setColumns(columns);
    chartView.setRows([row]);

    // Create the Gauge.
    var chart = new google.visualization.Gauge(element);

    chart.draw(chartView, {height: gaugeSize, 
                           max: maxValue, 
                           greenFrom: 0, 
                           greenTo: maxGreen, 
                           yellowFrom: (maxGreen + 1), 
                           yellowTo: maxYellow, 
                           redFrom: (maxYellow + 1), 
                           redTo: maxValue});
  }
  return {
    // Public interface to this function. 
    draw : draw
  };
}


